/**
 * grade.js
 * 获取年级
 *
 * created by qiuwei
 * version 1.0.0
 * 2016年03月29日
 */

import * as CONSTANTS from '../../constants/API';
import rp from '../requestProxy';
import { HTTP_RESULT } from '../../constants/protocol';

/**
 * 获取年级
 * @return {promise} 获取所有年级
 */
export default function grade() {
	let url = `${CONSTANTS.HOST}${CONSTANTS.ENUM_ON_SERVER}`;
	let body = {
		'target': 'teacher-grade',
		'filter': []
	};

	return rp.post(url, body).then((data) => {

		// 创建年级映射
		const GRADE_MAP = {
			'初一': '六年级',
			'初二': '七年级',
			'初三': '八年级',
			'初四': '九年级'
		};

		for(var obj of data.data) {
			if(GRADE_MAP[obj.name]) {
				obj.name = GRADE_MAP[obj.name];
			}
		}

		return data;
	});
}